/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 21626
 * Date: 2024-09-26
 * Time: 16:29
 */

/**
 * 泛型类
 * 1.<T></>当前类是个泛型类
 * @param <T>
 */

class MyArry<T extends Number> {        //泛型只有上界，没有下界
    public Object[] arry = new Object[3];
    public void setArry(int pos,T val){
        arry[pos] = val;
    }
    public T getVal(int pos){
        return (T)arry[pos];
    }
}

public class Test1 {
    public static void main(String[] args) {

    }
    public static void main4(String[] args) {
        MyArry<Integer> myArry1 = new MyArry<Integer>();        //指定myArry1只能表示整数
        myArry1.setArry(0,12);
        Integer a = myArry1.getVal(0);
        System.out.println(a);
        //MyArry<String> myArry2 = new MyArry<String>();
        //myArry2.setArry(0,"hehe");
        //myArry2.setArry(1,"world");       String不属于Number
    }
    public static void main3(String[] args) {
        Integer a = 100;
        Integer b = 100;
        System.out.println(a == b);
        Integer aa = 200;
        Integer bb = 200;
        System.out.println(aa == bb);
    }
    public static void main2(String[] args) {
        Integer a = 10;
        int i = a;      //自动拆箱

        int ii = a.intValue();
    }
    public static void main1(String[] args) {
        int i = 10;
        Integer a = i;      //（自动）装包
        Integer b = Integer.valueOf(i);     //显示装包
    }
}
